{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ecb430b8-bce2-4323-a1a1-46dfa460bedc",
   "metadata": {},
   "source": [
    "<center><img src=\"./image/CLBLOGO.jpg\" alt=\"创乐博\" style=\"width: 300px;\"/></center>\n",
    "\n",
    "# 40.16X16点阵模块显示实验\n",
    "\n",
    "@－－－－湖南创乐博智能科技有限公司－－－－<br>\n",
    "@  文件名：40.16X16点阵模块显示实验.py <br>\n",
    "@  版本：V2.0 <br>\n",
    "@  author: zhulin<br>\n",
    "@  说明：16X16点阵模块显示实验\n",
    "16X16点阵模块显示实验，通过第三方自定义的adafruit_vl53l0x库操作该传感器模块，该传感器模块采用的是I2C的通讯方式，可以打印出测量的距离值！！！<br>"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f0728e25-f41e-4c7d-86ce-58909756ffce",
   "metadata": {},
   "source": [
    "## 1.导入必要的库文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "fca2c6c3-1993-4c53-8b7c-5ca0bea57e58",
   "metadata": {},
   "outputs": [],
   "source": [
    "import board\n",
    "import time\n",
    "from PIL import Image\n",
    "from adafruit_ht16k33 import matrix"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65a659d6-0e47-4e69-a2ac-86887ecc84ad",
   "metadata": {},
   "source": [
    "## 2.实例化两个16x8的点阵模块"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "3f4b4c08-3966-4336-b1da-0bf5a01886b1",
   "metadata": {},
   "outputs": [],
   "source": [
    "i2c = board.I2C()\n",
    "matrix1 = matrix.MatrixBackpack16x8(i2c)\n",
    "matrix2 = matrix.MatrixBackpack16x8(i2c, address=0x71)\n",
    "# 清空显示\n",
    "matrix1.fill(0)\n",
    "matrix2.fill(0)\n",
    "# 设置闪烁频率和亮度\n",
    "display.blink_rate = 3\n",
    "display.brightness = 0.5\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7158cf42-def2-4fee-b8d8-0906631333c7",
   "metadata": {},
   "source": [
    "## 3. 功能函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dc65608e-37e5-46db-b45f-0eeb1bfade17",
   "metadata": {},
   "outputs": [],
   "source": [
    "def matrix_display():\n",
    "    # 显示第一个字\n",
    "    image1 = Image.open(\"./images/1_01.png\")\n",
    "    image2 = Image.open(\"./images/1_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "    # 显示第二个字\n",
    "    image1 = Image.open(\"./images/2_01.png\")\n",
    "    image2 = Image.open(\"./images/2_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "    # 显示第三个字\n",
    "    image1 = Image.open(\"./images/3_01.png\")\n",
    "    image2 = Image.open(\"./images/3_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "    # 显示第三个字\n",
    "    image1 = Image.open(\"./images/4_01.png\")\n",
    "    image2 = Image.open(\"./images/4_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "    # 显示第三个字\n",
    "    image1 = Image.open(\"./images/5_01.png\")\n",
    "    image2 = Image.open(\"./images/5_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "    # 显示第三个字\n",
    "    image1 = Image.open(\"./images/6_01.png\")\n",
    "    image2 = Image.open(\"./images/6_02.png\")\n",
    "    matrix1.image(image1)\n",
    "    matrix2.image(image2)\n",
    "    for count in range(16):\n",
    "        matrix1.shift_left(True)\n",
    "        matrix2.shift_left(True)\n",
    "        time.sleep(0.5)\n",
    "\n",
    "def makerobo_destroy():\n",
    "    matrix1.fill(0)\n",
    "    matrix2.fill(0)\n",
    "    \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e1396f0b-bbf8-428a-9051-7b3d0a445a29",
   "metadata": {},
   "source": [
    "## 4.主程序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "07a10273-8e00-4218-b297-73167ccfb7f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 程序入口\n",
    "if __name__ == '__main__':\n",
    "    try:\n",
    "        while True:\n",
    "            matrix_display()        #  点阵显示函数\n",
    "    except KeyboardInterrupt:  #  当按下Ctrl+C时，将执行destroy()子程序。\n",
    "        makerobo_destroy()     #  释放资源"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
